const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const Weather = sequelize.define('Weather', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  city: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '城市名称',
    index: true
  },
  province: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '省份'
  },
  adcode: {
    type: DataTypes.STRING(20),
    allowNull: false,
    comment: '行政区划代码'
  },
  weather: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '天气状况'
  },
  temperature: {
    type: DataTypes.STRING(10),
    allowNull: false,
    comment: '温度'
  },
  winddirection: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '风向'
  },
  windpower: {
    type: DataTypes.STRING(10),
    allowNull: false,
    comment: '风力等级'
  },
  humidity: {
    type: DataTypes.STRING(10),
    allowNull: false,
    comment: '湿度'
  },
  reporttime: {
    type: DataTypes.DATE,
    allowNull: false,
    comment: '报告时间'
  }
}, {
  tableName: 'weather',
  comment: '天气信息表',
  indexes: [
    {
      name: 'idx_city',
      fields: ['city']
    }
  ]
});

module.exports = Weather; 